package com.example.yingjiguanli_demo.controller;

import com.example.yingjiguanli_demo.aspect.interfaces.RateLimiter;
import com.example.yingjiguanli_demo.aspect.interfaces.RequirePermission;
import com.example.yingjiguanli_demo.pojo.Result;
import com.example.yingjiguanli_demo.pojo.UserRankingDTO;
import com.example.yingjiguanli_demo.service.IRankingsService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author scj
 * @since 2024-11-04
 */
@RestController
@RequestMapping("api/v1/rankings")
public class RankingsController {

    @Autowired
    private IRankingsService rankingsService;

    /**
     * 获取用户答题数量排名
     * @param pageNum  页码，从1开始
     * @param pageSize 每页条数
     * @return 用户答题排名列表
     */
    @ApiOperation(value = "目获取排行榜")
    @RequirePermission("user")
    @RateLimiter
    @GetMapping("/questions")
    public Result<List<UserRankingDTO>> getRankingsByQuestions(
            @RequestParam(defaultValue = "1") int pageNum,
            @RequestParam(defaultValue = "10") int pageSize) {
        return rankingsService.getRankingsByQuestions(pageNum, pageSize);
    }
}
